package com.wisezone.workflow.web;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.wisezone.common.annotation.WzFunAnnotation;
import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.utils.ConstantUtils;
import com.wisezone.workflow.bean.WfActivity;
import com.wisezone.workflow.bean.WfProcessDefinition;
import com.wisezone.workflow.bean.WfVariable;
import com.wisezone.workflow.bean.form.WfVariableForm;
import com.wisezone.workflow.bean.search.WfActivitySearch;
import com.wisezone.workflow.bean.search.WfVariableSearch;
import com.wisezone.workflow.exception.WfWebException;

/**
 * 变量控制类 2010-08-26
 * @author shan
 *
 */
@WzWebAnnotation(moduleName="variable")
public class WfVariableController extends WfWorkFlowController<WfVariable, 
WfVariableSearch,
WfVariableForm> {

	
	
	 private List<WfProcessDefinition> processDefList;
	 
	 private List<WfActivity> activityList;
	

	 /**
	  * 获得列表
	  * @return
	  * @throws Exception
	  */
	 public String list() throws WfWebException{
		 
		 searchEntity = getSearchEntity(true);
		 pagination = flowEngine.getWfVariableDao().listFormByPage(searchEntity);
		 return LIST;
	 }

	 
	 /**
	  * 进入新增
	  * @return
	  * @throws Exception
	  */
	 public String enterNew() throws WfWebException{
		
		 if(id != null){
			 entity = flowEngine.getWfVariableDao().load(id);
			 entity.setId(null);
		 }
		 return NEW_EDIT;
	 }
	 
	 /**
	  * 进入修改
	  * @return
	  * @throws Exception
	  */
	 public String enterEdit() throws WfWebException{
		 
		 entity = flowEngine.getWfVariableDao().load(id);
		 return NEW_EDIT;
	 }
	 
	 /**
	  * 进入查看
	  * @return
	  * @throws Exception
	  */
	 public String enterView() throws WfWebException{
		 
		 form = flowEngine.getWfVariableDao().loadForm(id);
		 return VIEW;
	 }
	 
	 /**
	  * 保存
	  * @return
	  * @throws Exception
	  */
	 public String save() throws WfWebException{

		 entity = getEntity();
		 this.flowEngine.getWfVariableDao().save(entity);
		 return getRedirect(LIST);
	 }
	 
	 /**
	  * 修改
	  * @return
	  * @throws Exception
	  */
	 public String update() throws WfWebException{
		 
		 entity = getEntity();
		 this.flowEngine.getWfVariableDao().update(entity);
		 return getRedirect(LIST);
	 }
	 
	 /**
	  * 删除
	  * @return
	  * @throws Exception
	  */
	 public String delete() throws WfWebException{
		 
		 Collection<Serializable> idList = getIdList();
		 if(idList != null){
			flowEngine.getWfVariableDao().deleteAllById(idList);
		 }
		 return getRedirect(LIST);
	 }

	@WzFunAnnotation(act = ConstantUtils.EXEC_AJAX)
	public List<WfProcessDefinition> getProcessDefList() {
		
		processDefList = flowEngine.getWfProcessDefinitionDao().getMaxVerList();
		return processDefList;
	}

	@WzFunAnnotation(act = ConstantUtils.EXEC_AJAX)
	public List<WfActivity> getActivityList() {
		
		WfActivitySearch activitySearch = new WfActivitySearch();
		searchEntity = getSearchEntity();
		activitySearch.setProcessDefId(searchEntity.getProcessDefId());
		activityList = flowEngine.getWfActivityDao().listAll(activitySearch);
		return activityList;
	}
	
	 
	 
	 
	 
	

	 
	
}
